import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:ywn_app/category/MovieCategory.dart';
import 'package:ywn_app/category/SelectedCategory.dart';
import 'package:ywn_app/contains/ThemeGlobal.dart';

class FriendPage extends StatefulWidget {
  @override
  _FriendPageState createState() => _FriendPageState();
}

class _FriendPageState extends State<FriendPage>
    with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  @override
  bool get wantKeepAlive => true;
  List<Tab> tabs = <Tab>[
    Tab(text: '精选'),
    Tab(text: '庆余年'),
    Tab(text: '电影'),
    Tab(text: '电视剧'),
    Tab(text: '综艺'),
    Tab(text: 'BLOG'),
    Tab(text: '小品'),
    Tab(text: '嘉年华'),
    Tab(text: '直播'),
    Tab(text: '动漫'),
    Tab(text: '博文'),
  ];
  TabController _controller;
  int selected = 0;

  @override
  void initState() {
    super.initState();
    _controller =
        TabController(length: tabs.length, vsync: this, initialIndex: selected);
    _controller.addListener(() {
      setState(() {
        selected = _controller.index;
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
          elevation: 0,
          backgroundColor: Colors.redAccent,
          actions: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 5),
              alignment: Alignment.center,
              width: MediaQuery.of(context).size.width,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  IconButton(
                      icon: Icon(
                        saomiaoshibie,
                        color: Colors.white,
                      ),
                      iconSize: 24,
                      padding: EdgeInsets.all(0),
                      onPressed: (){}
                  ),
                  Expanded(
                    child: Container(
                      decoration: BoxDecoration(
                        color: Colors.white24,
                        borderRadius: BorderRadius.circular(20)
                      ),
                      margin: EdgeInsets.only(left: 5,right: 5),
                      alignment: Alignment.center,
                      height: 32,
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: <Widget>[
                          Padding(padding: EdgeInsets.only(left: 10),
                            child: Icon(
                            sousuo,
                            size: 16,
                            color: Colors.white,
                          )),
                          Expanded(
                              child: Container(
                                alignment: Alignment.centerLeft,
                                padding: EdgeInsets.only(left: 4,right: 4),
                                child: Text('哪吒之魔童降世',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontWeight: FontWeight.w500,
                                    fontSize: 12,
                                  ),
                                ),
                              )
                          ),
                          Padding(padding: EdgeInsets.only(right: 10),child: Icon(
                            yuyin,
                            size: 16,
                            color: Colors.white,
                          ),)
                        ],
                      ),
                    ),
                  ),
                  IconButton(
                      padding: EdgeInsets.all(0),
                      icon: Icon(
                        shijian,
                        color: Colors.white,
                      ),
                      iconSize: 24,
                      onPressed: (){}),
                  IconButton(
                      padding: EdgeInsets.all(0),
                      icon: Icon(xinbaniconshangchuan,
                          color: Colors.white),
                      iconSize: 24,
                      onPressed: (){}),
                ],
              ),
            )
          ],
          bottom: PreferredSize(
              child: Stack(
                alignment: Alignment.center,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(left: 5, right: 45),
                    child: TabBar(

                      labelPadding: EdgeInsets.symmetric(horizontal: 10),
                      isScrollable: true,
                      unselectedLabelStyle:
                          TextStyle(fontSize: 18, fontWeight: FontWeight.w400),
                      labelStyle:
                          TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                      unselectedLabelColor: Colors.white70,
                      labelColor: Colors.white,
                      indicatorColor: Colors.white,
                      indicatorWeight: 2,
                      indicatorPadding: EdgeInsets.all(8),
                      indicatorSize: TabBarIndicatorSize.label,
                      tabs: tabs,
                      dragStartBehavior: DragStartBehavior.down,
                      controller: _controller,
                      onTap: (index) {
                        print(index);
                      },
                    ),
                  ),
                  Positioned(
                      right: 0,
                      child: IconButton(
                          icon: Icon(
                            Icons.list,
                            color: Colors.white,
                            size: 26,
                          ),
                          onPressed: () {
                            print("更多");
                          }))
                ],
              ),
              preferredSize: Size(MediaQuery.of(context).size.width,
                  MediaQuery.of(context).padding.top+10))),
      body: TabBarView(controller: _controller, children: [
        SelectedCategory(),
        MovieCateGory(),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
        Center(
          child: Text(
            'This is the tab',
            style: const TextStyle(fontSize: 25),
          ),
        ),
      ]),
    );
  }
}
